<?php
    
    class LSourceFiles {
        
        private $source_type;
        private $data;
        
        public function __construct($type, $data ){
            $this->source_type = $type;
            $this->data = $data;
        }
        
        public function getSourceFiles(){
           
            $return_data = false;
            $n = 0;
            
            $files = explode('#', $this->data[0]['source']);
            
            if(strtolower($this->source_type) == "all"){
               
                $return_data = array();
                foreach($files as $file){
                    list($file_, $ext) = explode('.', $file);
                        $path = FILES_PATH . $this->data[0]['id'] . "/" . $ext . "/" . $file_ . "." .$ext;
                        if(file_exists($path)){
                            $return_data[$n]['type'] = $ext;
                            $return_data[$n]['link_type'] = $this->source_type;
                            $return_data[$n]['filename'] = $path;
                            $return_data[$n]['content'] = file_get_contents($path);
                            $n++;
                        }else{
                            print $path . " NOT Exists<br/>";
                        }
                }
                
            }
            else{
                $return_data = array();
                foreach($files as $file){
                    list($file_, $ext) = explode('.', $file);
                    if($ext == strtolower($this->source_type)){
                        $path = FILES_PATH . $this->data[0]['id'] . "/" . $ext . "/" . $file_ . "." .$ext;
                        if(file_exists($path)){
                            $return_data[$n]['type'] = $ext;
                            $return_data[$n]['link_type'] = $this->source_type;
                            $return_data[$n]['filename'] = $path;
                            $return_data[$n]['content'] = file_get_contents($path);
                            $n++;
                        }else{
                            print $path . " NOT Exists<br/>";
                        }
                    }
                }
            }
           
           return $return_data;
            
        }
        
    }
    
?>